package com.wyp168.leetcode;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName LetterCasePermutationSolution
 * @Title TODO
 * @Description TODO
 * @Author wyp168
 * @Date 2022/10/30 00:18
 */
public class LetterCasePermutationSolution {
    public static void main(String[] args) {
        LetterCasePermutationSolution solution = new LetterCasePermutationSolution();
        String s = "a1b2c3";
        List<String> list = solution.letterCasePermutation(s);
        list.forEach(System.out::println);
    }


    public List<String> letterCasePermutation(String s) {
        List<String> resultList = new ArrayList<>();
        char[] chars = s.toCharArray();
        dfs(chars, 0, resultList);
        return resultList;
    }


    public void dfs(char[] chars, int index, List<String> resultList) {
        if (index == chars.length) {
            resultList.add(new String(chars));
            return;
        }
        if (chars[index] >= 'a' && chars[index] <= 'z') {
            dfs(chars, index + 1, resultList);
            chars[index] = (char) (chars[index] - 32);
            dfs(chars, index + 1, resultList);
        } else if (chars[index] >= 'A' && chars[index] <= 'Z') {
            dfs(chars, index + 1, resultList);
            chars[index] = (char) (chars[index] + 32);
            dfs(chars, index + 1, resultList);
        } else {
            dfs(chars, index + 1, resultList);
        }
    }
}
